package main

import "fmt"

func contains(nums []int, target int) bool {
	for _, number := range nums {
		if number == target {
			return true
		}
	}

	return false
}

func dfs(result *[][]int, list []int, nums []int) {
	if len(list) == len(nums) {
		*result = append(*result, list)
		return
	}

	for i := 0; i < len(nums); i++ {
		//判断数组中是否包含一个元素
		if contains(list, nums[i]) {
			continue
		}

		list = append(list, nums[i])

		dfs(result, list, nums)

		list = list[:len(list)-1]
	}

}

func permutations(nums []int) [][]int {
	if len(nums) == 0 || nums == nil {
		return nil
	}

	var result [][]int

	var list []int

	dfs(&result, list, nums)

	return result
}

// 排列 指定数组中的元素进行排列
func main() {
	nums := []int{1, 2, 3}

	result := permutations(nums)

	fmt.Println(result)
}
